﻿Public Class MASPARTXRAY
    Private SXRYID = Nothing
    Private CXRYID = Nothing
    Private CODE = Nothing
    Private SXRYNAME = Nothing
    Private STATUS = Nothing

    Private selectMaspartxray = "SELECT `sxryid` as 'ID ส่วน' ,masclsxray.`CXRYNAME` as 'ชื่อประเภท', maspartxray.`code` as 'CODE', `sxryname` as 'ชื่อส่วน', masclsxray.`status` as 'สถานะการเปิดใช้งาน',masclsxray.`cxryid` as 'ID ประเภท' FROM maspartxray LEFT JOIN (SELECT * FROM  masclsxray) as masclsxray ON maspartxray.cxryid = masclsxray.cxryid  "
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property SXRYID_() As Integer
        Get
            Return SXRYID
        End Get
        Set(value As Integer)
            SXRYID = value
        End Set
    End Property

    Property CXRYID_() As Integer
        Get
            Return CXRYID
        End Get
        Set(value As Integer)
            CXRYID = value
        End Set
    End Property

    Property CODE_() As String
        Get
            Return CODE
        End Get
        Set(value As String)
            CODE = value
        End Set
    End Property

    Property SXRYNAME_() As String
        Get
            Return SXRYNAME
        End Get
        Set(value As String)
            SXRYNAME = value
        End Set
    End Property

    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMaspartxray_() As String
        Get
            Return selectMaspartxray
        End Get
        Set(value As String)

        End Set
    End Property
    Public Sub loadcombobox(ByVal MaspartxrayCmb As ComboBox)
        Dim MASCLSXRAY As DataTable
        MASCLSXRAY = connect.GetTable("SELECT `cxryid`, `cxryname` FROM masclsxray WHERE `status` = 1 ")
        Try
            With MaspartxrayCmb
                .DataSource = MASCLSXRAY
                .DisplayMember = "cxryname"
                .ValueMember = "cxryid"
                '.BindingContext = BindingContext
            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Public Sub insertMaspartxrayData()
        If TypeOf CODE Is String And TypeOf SXRYNAME Is String Then
            If connect.GetTable("SELECT `sxryid` FROM maspartxray WHERE  `cxryid` = '" & CXRYID & "' AND `code` = '" & CODE & "' AND `sxryname` = '" & SXRYNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO maspartxray (`cxryid`,`code`, `sxryname`, `status`) VALUES ('" & CXRYID & "','" & CODE & "', '" & SXRYNAME & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลส่วนเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub

    Public Sub editMaspartxrayData()
        If TypeOf CODE Is String And TypeOf SXRYNAME Is String Then

            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()
                connect.ExecuteNonQuery("UPDATE maspartxray SET `cxryid` = '" & CXRYID & "',`code` = '" & CODE & "', `sxryname` = '" & SXRYNAME & "', `status` = '" & STATUS & "' WHERE `sxryid` = '" & SXRYID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลส่วนเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()

        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
